home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / gemfut15.lzh / AESUTFM1.C < prev    next >
C/C++ Source or Header  |  1990-05-26  |  10KB  |  270 lines

  1.  
  2. /**************************************************************************
  3.  *
  4.  * AESFAST PD utilties
  5.  *
  6.  *  AESUTFM1 - Forms processing utilties.
  7.  *    frm_dsdial - Form Dynamic String Dialog.
  8.  *************************************************************************/
  9.  
  10. #if 0                       /* Set to 0 if not using GemFast system */
  11.   #include <gemfast.h>
  12. #else
  13.   #include <gemdefs.h>
  14.   #include <obdefs.h>
  15. #endif
  16.  
  17. #ifndef NULL
  18. #define NULL 0L
  19. #endif
  20.  
  21. #ifndef TRUE
  22. #define TRUE  1
  23. #define FALSE 0
  24. #endif
  25.  
  26. #define MAX_BUTTONS 5
  27. #define MAX_STRINGS 20
  28.  
  29. /*-------------------------------------------------------------------------
  30.  * Object tree for dynamic dialog box...
  31.  *-----------------------------------------------------------------------*/
  32.  
  33. static OBJECT dialtree[] = {
  34.   -1,  1, 21, G_BOX,    NONE,   OUTLINED, 0x00021100L, 0x0000, 0x0000, 0x0021, 0x0017,
  35.    2, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x0001, 0x0001, 0x0001,
  36.    3, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x0002, 0x0001, 0x0001,
  37.    4, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x0003, 0x0001, 0x0001,
  38.    5, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x0004, 0x0001, 0x0001,
  39.    6, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x0005, 0x0001, 0x0001,
  40.    7, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x0006, 0x0001, 0x0001,
  41.    8, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x0007, 0x0001, 0x0001,
  42.    9, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x0008, 0x0001, 0x0001,
  43.   10, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x0009, 0x0001, 0x0001,
  44.   11, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x000A, 0x0001, 0x0001,
  45.   12, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x000B, 0x0001, 0x0001,
  46.   13, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x000C, 0x0001, 0x0001,
  47.   14, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x000D, 0x0001, 0x0001,
  48.   15, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x000E, 0x0001, 0x0001,
  49.   16, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x000F, 0x0001, 0x0001,
  50.   17, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x0010, 0x0001, 0x0001,
  51.   18, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x0011, 0x0001, 0x0001,
  52.   19, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x0012, 0x0001, 0x0001,
  53.   20, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x0013, 0x0001, 0x0001,
  54.   21, -1, -1, G_STRING, NONE,   NORMAL,   NULL,        0x0001, 0x0014, 0x0001, 0x0001,
  55.    0, 22, 26, G_IBOX,   NONE,   NORMAL,   0x00001100L, 0x0001, 0x0015, 0x0001, 0x0001,
  56.   23, -1, -1, G_BUTTON, 0x0005, NORMAL,   NULL,        0x0000, 0x0000, 0x0001, 0x0001,
  57.   24, -1, -1, G_BUTTON, 0x0005, NORMAL,   NULL,        0x0000, 0x0000, 0x0001, 0x0001,
  58.   25, -1, -1, G_BUTTON, 0x0005, NORMAL,   NULL,        0x0000, 0x0000, 0x0001, 0x0001,
  59.   26, -1, -1, G_BUTTON, 0x0005, NORMAL,   NULL,        0x0000, 0x0000, 0x0001, 0x0001,
  60.   21, -1, -1, G_BUTTON, 0x0025, NORMAL,   NULL,        0x0000, 0x0000, 0x0001, 0x0001
  61.   };                                            
  62.  
  63. #define DIALSTL1 1      /* String Line 1                */
  64. #define DIALPBXB 21     /* Parent Box for exit buttons  */
  65. #define DIALBX01 22     /* First exit button            */
  66.  
  67. /**************************************************************************
  68.  *
  69.  * count_strings - Count strings and keep track of the longest one.
  70.  *
  71.  *************************************************************************/
  72.  
  73. static int
  74. count_strings(pstrings, maxstrings, pmaxlen)
  75.     register char   **pstrings;
  76.     register int    maxstrings;
  77.     int             *pmaxlen;
  78. {
  79.     register int    numstrings;
  80.     register int    wrklen;
  81.     register int    maxlen;
  82.     
  83.     for (numstrings = 0, maxlen = 0; 
  84.          numstrings < maxstrings && **pstrings != 0x00; 
  85.          numstrings++,
  86.          pstrings++) {
  87.  
  88.             if (maxlen < (wrklen = strlen(*pstrings))) {
  89.                 maxlen = wrklen;
  90.             }
  91.     }
  92.     
  93.     *pmaxlen = maxlen;
  94.     return numstrings;
  95. }
  96.        
  97. /**************************************************************************
  98.  *
  99.  * frm_dsdial - Form dynamic string dialog.
  100.  *
  101.  *************************************************************************/
  102.  
  103. int
  104. frm_dsdial(pstrings, pbuttons, graphicsflag)
  105.     char             *pstrings[];
  106.     char             *pbuttons[];
  107.     int              graphicsflag;
  108. {
  109.     int              dmy;
  110.     int              xbwidth;
  111.     int              slen;
  112.     register int     sizechar;
  113.     register int     counter;
  114.     register int     numobs;
  115.     register int     pixlen;
  116.     register OBJECT  *ptree;
  117.     register char    **pwrk;
  118.     static   int     initdone = 0;
  119.     static   int     wchar;
  120.     static   int     hchar;
  121.     
  122. /*-------------------------------------------------------------------------
  123.  * Init the xywh values in the object tree, get the system character sizes
  124.  * for later usage, adjust the top line to be 1/2 char up from the rest. 
  125.  *-----------------------------------------------------------------------*/
  126.  
  127.     if (!initdone) {
  128.         initdone = 1;
  129. #ifdef AESFAST_A
  130.         rsc_treefix(dialtree);
  131. #else
  132.         ptree = dialtree;
  133.         for (counter = 0; (ptree[counter].ob_flags & LASTOB) == FALSE; counter++) {
  134.             rsrc_obfix(ptree, counter);
  135.         }
  136. #endif
  137.         graf_handle(&wchar, &hchar, &dmy, &dmy);
  138.         dialtree[DIALSTL1].ob_y -= (hchar >> 1);       
  139.     }
  140.  
  141. /*-------------------------------------------------------------------------
  142.  * Count the button strings, find the longest one, distribute the buttons
  143.  * evenly within their parent box, make the rightmost the default button.
  144.  * (We place a gutter of 2 character widths on each side of each button.) 
  145.  *-----------------------------------------------------------------------*/
  146.  
  147.     {
  148.         register int obx;
  149.  
  150.         numobs = count_strings(pbuttons, MAX_BUTTONS, &slen);
  151.  
  152.         sizechar = wchar;
  153.         pixlen   = (slen + 2) * sizechar;
  154.         sizechar <<= 1;
  155.         xbwidth  = (numobs * pixlen) + ((numobs + 1) * sizechar);
  156.         
  157.         for (counter   = 0, 
  158.                obx     = sizechar,
  159.                pwrk    = pbuttons, 
  160.                ptree   = &dialtree[DIALBX01]
  161.                ;
  162.              counter < MAX_BUTTONS
  163.                ; 
  164.              counter++, 
  165.                obx += pixlen + sizechar,
  166.                ptree++ 
  167.                ) {
  168.  
  169.             ptree->ob_flags &= ~DEFAULT;
  170.  
  171.             if (counter < numobs) {
  172.                 ptree->ob_flags &= ~HIDETREE;
  173.                 ptree->ob_x     = obx;
  174.                 ptree->ob_spec  = (long)*pwrk++;
  175.                 ptree->ob_width = pixlen;
  176.             } else {
  177.                 ptree->ob_flags |= HIDETREE;
  178.             }
  179.         }
  180.     
  181.     dialtree[DIALPBXB+numobs].ob_flags |= DEFAULT;
  182.     
  183.     }
  184.      
  185. /*-------------------------------------------------------------------------
  186.  * Count the dialog strings, find the largest, calc the size of the 
  187.  * dialog box and the placement of the buttons at the bottom.  If space
  188.  * permits, we leave a 1-line gutter between the last dialog string and
  189.  * the buttons, but if all 20 dialog strings are used, then the buttons
  190.  * are jammed right up against the bottom string.
  191.  *-----------------------------------------------------------------------*/
  192.  
  193.     { 
  194.         register int btnadjust;
  195.         
  196.         numobs    = count_strings(pstrings, MAX_STRINGS, &slen);
  197.  
  198.         btnadjust = (numobs < MAX_STRINGS); /* button padding, if space allows */
  199.     
  200.         pixlen    = (slen + 2) * wchar;
  201.         pixlen    = (pixlen > xbwidth) ? pixlen : xbwidth;
  202.  
  203.         sizechar  = hchar;
  204.         
  205.         ptree            = dialtree;
  206.         ptree->ob_width  = pixlen;
  207.         ptree->ob_height = (numobs + 3 + btnadjust) * sizechar;
  208.  
  209.         ptree            = &dialtree[DIALPBXB];
  210.         ptree->ob_x      = (pixlen - xbwidth) >> 1;
  211.